﻿using System.Collections.Generic;
using System.Data;

namespace S2_Xxxx_XxxNetApi
{
    public interface IDapperHelper
    {
        /// <summary>
        /// 通过sql数据获取数据
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public DataTable GetBySql(string sql);

        /// <summary>
        /// 执行sql语句
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public int ExecuteSql(string sql);

        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageNumber">页码</param>
        /// <param name="pageCount">总页数</param>
        /// <returns></returns>
        public DataTable GetByPage(string sql, int pageSize, int pageNumber, out int pageCount);
    }

    public interface IDapperHelper<T> 
    {
        /// <summary>
        /// 获取全部数据
        /// </summary>
        /// <returns></returns>
        public List<T> Get();

        /// <summary>
        /// 根据条件获取数据
        /// </summary>
        /// <param name="where">条件(不需要前面带where字符串)</param>
        /// <returns></returns>
        public List<T> Get(string where);

        /// <summary>
        /// 排序获取数据
        /// </summary>
        /// <param name="where">条件(不需要前面带where字符串)</param>
        /// <param name="orderBy">排序字段</param>
        /// <param name="orderByType">排序类型：asc/desc</param>
        /// <returns></returns>
        public List<T> Get(string where, string orderBy, string orderByType);

        /// <summary>
        /// 获取前几行数据
        /// </summary>
        /// <param name="where">条件(不需要前面带where字符串)</param>
        /// <param name="orderBy">排序字段</param>
        /// <param name="orderByType">排序类型：asc/desc</param>
        /// <param name="topNumber">前多少条数据</param>
        /// <returns></returns>
        public List<T> Get(string where, string orderBy, string orderByType, int topNumber);

        /// <summary>
        /// 获取全部总行数
        /// </summary>
        /// <returns></returns>
        public int GetCount();

        /// <summary>
        /// 根据条件获取总行数
        /// </summary>
        /// <param name="where"></param>
        /// <returns></returns>
        public int GetCount(string where);

        /// <summary>
        /// 获取第一行数据
        /// </summary>
        /// <param name="where">条件(不需要前面带where字符串)</param>
        /// <returns></returns>
        public T GetFirst(string where);

        /// <summary>
        /// 获取第一行数据
        /// </summary>
        /// <param name="where">条件(不需要前面带where字符串)</param>
        /// <param name="orderBy">排序字段</param>
        /// <param name="orderByType">排序类型：asc/desc</param>
        /// <returns></returns>
        public T GetFirst(string where, string orderBy, string orderByType);

        /// <summary>
        /// 获取分页数据
        /// </summary>
        /// <param name="where">条件(不需要前面带where字符串)</param>
        /// <param name="orderBy">排序字段</param>
        /// <param name="orderByType">排序类型：asc/desc</param>
        /// <param name="pageSize">页大小</param>
        /// <param name="pageNumber">页码</param>
        /// <param name="pageCount">总页数</param>
        /// <returns></returns>
        public List<T> GetByPage(string where, string orderBy, string orderByType, int pageSize, int pageNumber, out int pageCount);

        /// <summary>
        /// 通过sql数据获取数据
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public DataTable GetBySql(string sql);

        /// <summary>
        /// 执行sql语句
        /// </summary>
        /// <param name="sql">sql语句</param>
        /// <returns></returns>
        public int ExecuteSql(string sql);

        /// <summary>
        /// 判断数据是否存在
        /// </summary>
        /// <param name="where">条件(不需要前面带where字符串)</param>
        /// <returns></returns>
        public bool Exist(string where);

        /// <summary>
        /// 新增数据
        /// </summary>
        /// <param name="model">数据对象</param>
        /// <returns></returns>
        public bool Insert(T model);

        /// <summary>
        /// 批量新增数据
        /// </summary>
        /// <param name="listModel">数据对象集合</param>
        /// <returns></returns>
        public bool Insert(List<T> listModel);

        /// <summary>
        /// 修改数据
        /// </summary>
        /// <param name="model">数据对象</param>
        /// <returns></returns>
        public bool Edit(T model);

        /// <summary>
        /// 批量修改数据
        /// </summary>
        /// <param name="listModel">数据对象集合</param>
        /// <returns></returns>
        public bool Edit(List<T> listModel);

        /// <summary>
        /// 删除数据
        /// </summary>
        /// <param name="model">数据对象</param>
        /// <returns></returns>
        public bool Delete(T model);

        /// <summary>
        /// 批量删除对象
        /// </summary>
        /// <param name="listModel">数据对象集合</param>
        /// <returns></returns>
        public bool Delete(List<T> listModel);
    }
}
